/**
 * 函数组合-调试
 */

const curry =  (func) => {
  const curriedFn = (...args) => {
    if (args.length < func.length) {
      return (...rest) => curriedFn(...[...args, ...rest])
    }
    return func(...args)
  }

  return curriedFn
}

const compose =  (...fns) => value =>
  fns.reverse().reduce((value, fn) => fn(value), value)

// 实现转换 NEVER SAY DIE -> never-say-die

// 先切割再转小写最后组合

const split = curry((sep, str) => str.split(sep))
const toLower = str => str.toLowerCase()
const join = curry((sep, arr) => arr.join(sep))
const map = curry((fn, arr) => arr.map(fn))

// 多个log时不容易区分打印的哪个数据
const log = v => {
  console.log(v)
  return v
}

// 用trace给打印数据加上标签
const trace = curry((tag, v) => {
  console.log(tag, v)
  return v
})

const f = compose(join('-'), trace('map 之后'), map(toLower), trace('split 之后'), split(' '))
console.log(f('NEVER SAY DIE'))

export {}
